package com.fyzk.activity.lottery.zc_new.adapter;


import android.app.ActionBar.LayoutParams;
import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.bean.ZCGameQueueItem;
import com.tyjc.lottery.R;
import com.fyzk.utils.TextStyleUtil;

import java.util.List;

public class ZCJQCAdapter_New extends ZCBaseAdapter{

	public ZCJQCAdapter_New(Context context, List<ZCGameQueueItem> infors) {
		super(context, infors);
		// TODO Auto-generated constructor stub
	}

	@Override
	protected View getRightView(final ZCGameQueueItem data, int position) {
		// TODO Auto-generated method stub
		View rightView = LayoutInflater.from(context).inflate(R.layout.zc_adapter_jqc, null);
		TextView home_tv =  (TextView) rightView.findViewById(R.id.zc_jqc_home);
		TextView away_tv = (TextView) rightView.findViewById(R.id.zc_jqc_away);
		TextView sheng_tv = (TextView) rightView.findViewById(R.id.zc_jqc_pl_sheng);
		TextView ping_tv = (TextView) rightView.findViewById(R.id.zc_jqc_pl_ping);
		TextView fu_tv = (TextView) rightView.findViewById(R.id.zc_jqc_pl_fu);
		final CheckBox home_qiu0_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_home_qiu0);
		final CheckBox home_qiu1_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_home_qiu1);
		final CheckBox home_qiu2_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_home_qiu2);
		final CheckBox home_qiu3_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_home_qiu3);
		final CheckBox away_qiu0_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_away_qiu0);
		final CheckBox away_qiu1_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_away_qiu1);
		final CheckBox away_qiu2_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_away_qiu2);
		final CheckBox away_qiu3_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_away_qiu3);
		final CheckBox quanBao_check = (CheckBox) rightView.findViewById(R.id.zc_jqc_quanbao);
		
		home_tv.setText(data.getHomeTeam());
		away_tv.setText(data.getAwayTeam());
		sheng_tv.setText("胜"+data.getVs_3());
		ping_tv.setText("平"+data.getVs_1());
		fu_tv.setText("负"+data.getVs_0());
		
		home_qiu0_check.setChecked(data.isCheckQiu0_home);
		home_qiu1_check.setChecked(data.isCheckQiu1_home);
		home_qiu2_check.setChecked(data.isCheckQiu2_home);
		home_qiu3_check.setChecked(data.isCheckQiu3_home);
		away_qiu0_check.setChecked(data.isCheckQiu0_away);
		away_qiu1_check.setChecked(data.isCheckQiu1_away);
		away_qiu2_check.setChecked(data.isCheckQiu2_away);
		away_qiu3_check.setChecked(data.isCheckQiu3_away);
		quanBao_check.setChecked(data.isCheckQiu_all);
		
	    
	    
	    home_qiu0_check.append(setTextStyle("0"));
	    home_qiu1_check.append(setTextStyle("1"));
	    home_qiu2_check.append(setTextStyle("2"));
	    home_qiu3_check.append(setTextStyle("3+"));
	    away_qiu0_check.append(setTextStyle("0"));
	    away_qiu1_check.append(setTextStyle("1"));
	    away_qiu2_check.append(setTextStyle("2"));
	    away_qiu3_check.append(setTextStyle("3+"));
	    
		home_qiu0_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu0_home = ! data.isCheckQiu0_home;
				if (data.isCheckQiu0_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		home_qiu1_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu1_home = ! data.isCheckQiu1_home;
				if (data.isCheckQiu1_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		home_qiu2_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu2_home = ! data.isCheckQiu2_home;
				if (data.isCheckQiu2_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		
		home_qiu3_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu3_home = ! data.isCheckQiu3_home;
				if (data.isCheckQiu3_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		away_qiu0_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu0_away = ! data.isCheckQiu0_away;
				if (data.isCheckQiu0_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		away_qiu1_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu1_away = ! data.isCheckQiu1_away;
				if (data.isCheckQiu1_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		away_qiu2_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu2_away = ! data.isCheckQiu2_away;
				if (data.isCheckQiu2_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		
		away_qiu3_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu3_away = ! data.isCheckQiu3_away;
				if (data.isCheckQiu3_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}
				
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});
		
		quanBao_check.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu_all = ! data.isCheckQiu_all;
				if (data.isCheckQiu_all) {
					data.ban_clickNum = 4;
					data.quan_clickNum = 4;
				}else{
					data.ban_clickNum = 0;
					data.quan_clickNum = 0;
				}
				data.isCheckQiu0_home = data.isCheckQiu_all;
				data.isCheckQiu1_home = data.isCheckQiu_all;
				data.isCheckQiu2_home = data.isCheckQiu_all;
				data.isCheckQiu3_home = data.isCheckQiu_all;
				data.isCheckQiu0_away = data.isCheckQiu_all;
				data.isCheckQiu1_away = data.isCheckQiu_all;
				data.isCheckQiu2_away = data.isCheckQiu_all;
				data.isCheckQiu3_away = data.isCheckQiu_all;
				
				home_qiu0_check.setChecked(data.isCheckQiu0_home);
				home_qiu1_check.setChecked(data.isCheckQiu1_home);
				home_qiu2_check.setChecked(data.isCheckQiu2_home);
				home_qiu3_check.setChecked(data.isCheckQiu3_home);
				away_qiu0_check.setChecked(data.isCheckQiu0_away);
				away_qiu1_check.setChecked(data.isCheckQiu1_away);
				away_qiu2_check.setChecked(data.isCheckQiu2_away);
				away_qiu3_check.setChecked(data.isCheckQiu3_away);
				tongJi();
			}
		});
		
		LinearLayout.LayoutParams pl = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, 
				LayoutParams.MATCH_PARENT, 1);
		rightView.setLayoutParams(pl);
		return rightView;
	}
	
	private SpannableString setTextStyle(String text){
		SpannableString spanString = TextStyleUtil.fontSizeSpan(new SpannableString(text), 18);
	    spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD);
	    return spanString;
	}

}
